package com.jobs.jsonDemo;

import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson2.JSONArray;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author 王博
 * @DateTime 2024-08-23 11:24
 */
public class JsonDemo {
    public static void main(String[] args) {
        List<CustomerDistributionObjectRoundDTO> list = new ArrayList<>();
        list.add(new CustomerDistributionObjectRoundDTO(1L, "111", 1));
        list.add(new CustomerDistributionObjectRoundDTO(2L, "222", 2));
        list.add(new CustomerDistributionObjectRoundDTO(3L, "333", 3));

        String jsonStr = JSONUtil.toJsonStr(list);
        System.out.println(jsonStr);

        String jsonString = JSONArray.toJSONString(list);
        System.out.println(jsonString);


        JSONArray jsonArray = JSONArray.parseArray(jsonStr);
        List<CustomerDistributionObjectRoundDTO> javaList = jsonArray.toJavaList(CustomerDistributionObjectRoundDTO.class);
        System.out.println(javaList);

        cn.hutool.json.JSONArray jsonArray1 = JSONUtil.parseArray(jsonStr);
        List<CustomerDistributionObjectRoundDTO> list1 = jsonArray1.toList(CustomerDistributionObjectRoundDTO.class);
        System.out.println(list1);
    }
}
